const app = getApp();
var that;
Page({

  /**
   * 页面的初始数据
   */
  // 使文本框进入可编辑状态
  data: {
    index1: '',
    inputShowed: false, //初始文本框不显示内容
    teachers: [],
    teacher: {},
    teacherID:'',
    openedid:'',
    img1: "img/1.png",
    img2: "img/2.png",
    img3: "img/3.png",
    img4: "img/4.png",
    img5: "img/5.png",
    img6: "img/6.png",
  },
  showInput: function() {
    this.setData({
      inputShowed: true //设置文本框可以输入内容
    });
  },
  // 取消搜索
  hideInput: function() {
    this.setData({
      inputShowed: false
    });
  },

  detail: function(event) {
    var id = event.currentTarget.dataset.item.openid;
    console.log(id,'iid');
    wx.request({
      url: 'https://www.enjoyyz.com:8443/yinzuo/search',
      method: 'GET',
      data: {
        key: id
      },
      header: {
        'content-type': 'application/x-www-form-encoded'
      },
      success(res) {
        console.log(res.data.data);
        app.globalData.searchResult = res.data.data;
        console.log(app.globalData.searchResult);
      }
    });
    wx.navigateTo({
      url: 'Details/details',
    });
  },

  search: function(e) {
    var id = e.detail.value;
    console.log(id);
    wx.request({
      url: 'https://www.enjoyyz.com:8443/yinzuo/search',
      method: 'GET',
      data: {
        key: id
      },
      header: {
        'content-type': 'application/x-www-form-encoded'
      },
      success(res) {
        console.log(res.data.data);
        app.globalData.searchResult = res.data.data;
        console.log(app.globalData.searchResult);
       
      }
    });
    wx.navigateTo({
      url: 'Details/details',
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function() {
    const url = 'https://www.enjoyyz.com:8443/yinzuo/recommend'
    var teachers = app.globalData.teachers;
    console.log(teachers);
    wx.request({
      url: url,
      success: res => {
        that = this;
        console.log(res.data.data,'res.data.data')
        this.setData({
          teachers: teachers,
          teachers: res.data.data,
        }) 
        console.log(this.data.teachers,'this.data.teachers')
      }
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})